import { S } from "mockjs";

const getRandomInt = (min : number, max : number) : number => {
  return Math.floor(Math.random() * (max - min + 1)) + min;
};
const getRandomDate = (start : string, end : string) : string => {
  const startDate = new Date(start);
  const endDate = new Date(end);
  const randomDate = new Date(
    startDate.getTime() +
      Math.random() * (endDate.getTime() - startDate.getTime())
  );
  return randomDate.toISOString().split("T")[0];
};
export default {
  getTableData: () => {
    const brands = ["产品1", "产品2", "产品3", "产品4", "产品5", "产品6"];
    const tableData = brands.map((brand) => ({
      name: brand,
      todayBuy: getRandomInt(100, 1500),
      monthBuy: getRandomInt(1000, 7000),
      totalBuy: getRandomInt(10000, 70000),
    }));

    return {
      code: 200,
      data: {
        tableData: tableData,
      },
    };
  },
  getCountData: () => {
    return {
      code: 200,
      data: [
        {
          name: "今日支付订单",
          value: getRandomInt(100, 1500),
          icon: "SuccessFilled",
          color: "#2ec7c9",
        },
        {
          name: "今日收藏订单",
          value: getRandomInt(100, 1500),
          icon: "StarFilled",
          color: "#ffb980",
        },
        {
          name: "今日未支付订单",
          value: getRandomInt(100, 1500),
          icon: "GoodsFilled",
          color: "#5ab1ef",
        },
        {
          name: "本月支付订单",
          value: getRandomInt(100, 1500),
          icon: "SuccessFilled",
          color: "#2ec7c9",
        },
        {
          name: "本月收藏订单",
          value: getRandomInt(100, 1500),
          icon: "StarFilled",
          color: "#ffb980",
        },
        {
          name: "本月未支付订单",
          value: getRandomInt(100, 1500),
          icon: "GoodsFilled",
          color: "#5ab1ef",
        },
      ],
    };
  },
  getChartData: () => {

    const brands = ["产品1", "产品2", "产品3", "产品4", "产品5", "产品6"];
    const videoBrands = ["产品1", "产品2", "产品3", "产品4", "产品5", "产品6"];;
    const daysOfWeek = ["周一", "周二", "周三", "周四", "周五", "周六", "周日"];

    const generateOrderData = () => {
      const date = [];
      const data = [];

      for (let i = 0; i < 7; i++) {
        date.push(getRandomDate("2025-1-01", "2025-1-07"));
      }

      for (let i = 0; i < 7; i++) {
        const brandData : {[key : string] : number} = {};
        brands.forEach((brand) => {
          brandData[brand] = getRandomInt(1000, 5000);
        });
        data.push(brandData);
      }

      return { date, data };
    };

    const generateVideoData = () => {
      return videoBrands.map((brand) => ({
        name: brand,
        value: getRandomInt(1000, 5000),
      }));
    };

    const generateUserData = () => {
      return daysOfWeek.map((day) => ({
        date: day,
        new: getRandomInt(1, 100),
        active: getRandomInt(100, 1000),
      }));
    };

    return {
      code: 200,
      data: {
        orderData: generateOrderData(),
        videoData: generateVideoData(),
        userData: generateUserData(),
      },
    };
  },
};
